package com.huawei.common.config;

import com.huawei.common.utils.ThreadLocalUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class DefaultFeignClient {
    @Bean
    public RequestInterceptor userInfoInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                String[] user = ThreadLocalUtil.get();
                if(user != null){
                    requestTemplate.header("id", user[0]);
                    requestTemplate.header("username", user[1]);
                }
            }
        };
    }
}
